"""Initial

Revision ID: 5f0e0e8ea5ac
Revises: 
Create Date: 2023-01-28 07:48:42.524086

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5f0e0e8ea5ac'
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('admin_user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=100), nullable=True),
    sa.Column('password', sa.String(length=100), nullable=True),
    sa.Column('name', sa.String(length=100), nullable=True),
    sa.Column('can_create_admins', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('can_export', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('can_delete', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('can_edit', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('can_add', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('can_view_files', sa.Boolean(), server_default='0', nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email')
    )
    op.create_table('category',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('name_eng', sa.String(length=50), nullable=False),
    sa.Column('price_4h', sa.Float(), nullable=False),
    sa.Column('price_1d', sa.Float(), nullable=False),
    sa.Column('price_1w', sa.Float(), nullable=False),
    sa.Column('price_2w', sa.Float(), nullable=False),
    sa.Column('price_1m', sa.Float(), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('country',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('name_eng', sa.String(length=50), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('provider',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('name_eng', sa.String(length=50), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('site',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('stats',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('day', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('mobile_proxies_bought', sa.Integer(), server_default='0', nullable=True),
    sa.Column('server_proxies_bought', sa.Integer(), server_default='0', nullable=True),
    sa.Column('payments_payed', sa.Integer(), server_default='0', nullable=True),
    sa.Column('messages_sent', sa.Integer(), server_default='0', nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('day')
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('telegram_id', sa.BigInteger(), nullable=True),
    sa.Column('username', sa.String(length=50), nullable=True),
    sa.Column('is_banned', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('is_registered', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('balance', sa.Float(), server_default='0', nullable=True),
    sa.Column('email', sa.String(length=100), nullable=True),
    sa.Column('lang_code', sa.Enum('en', 'ru'), server_default='ru', nullable=True),
    sa.Column('was_registered', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('telegram_id')
    )
    op.create_table('allowed_ip',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('ip_address', sa.String(length=255), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('ip_address')
    )
    op.create_table('city',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=50), nullable=False),
    sa.Column('name_eng', sa.String(length=50), nullable=False),
    sa.Column('country_id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['country_id'], ['country.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('payment',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('summ', sa.Float(), nullable=False),
    sa.Column('status', sa.Enum('paid', 'waiting_payment', 'payment_failed'), server_default='waiting_payment', nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('sites_categories',
    sa.Column('category_id', sa.Integer(), nullable=True),
    sa.Column('site_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
    sa.ForeignKeyConstraint(['site_id'], ['site.id'], )
    )
    op.create_table('order',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('active', 'archive'), server_default='active', nullable=True),
    sa.Column('summ', sa.Float(), nullable=False),
    sa.Column('summ_total', sa.Float(), nullable=False),
    sa.Column('period', sa.Enum('four_hours', 'one_day', 'one_week', 'two_weeks', 'one_month', name='orderperiod'), nullable=False),
    sa.Column('was_created', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('category_id', sa.Integer(), nullable=True),
    sa.Column('site_id', sa.Integer(), nullable=True),
    sa.Column('country_id', sa.Integer(), nullable=True),
    sa.Column('city_id', sa.Integer(), nullable=True),
    sa.Column('provider_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('auto_renew', sa.Boolean(), server_default='0', nullable=True),
    sa.Column('expiring_on', sa.DateTime(), nullable=False),
    sa.Column('was_renewed', sa.DateTime(), nullable=True),
    sa.Column('last_notified', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
    sa.ForeignKeyConstraint(['city_id'], ['city.id'], ),
    sa.ForeignKeyConstraint(['country_id'], ['country.id'], ),
    sa.ForeignKeyConstraint(['provider_id'], ['provider.id'], ),
    sa.ForeignKeyConstraint(['site_id'], ['site.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('server',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('description', sa.String(length=255), nullable=True),
    sa.Column('ip_address', sa.String(length=100), nullable=False),
    sa.Column('config_path', sa.String(length=50), nullable=False),
    sa.Column('proxy_type', sa.Enum('mobile', 'server', name='servertype'), nullable=False),
    sa.Column('proxy_privacy', sa.Enum('private', 'shared', name='serverprivacy'), nullable=False),
    sa.Column('provider_id', sa.Integer(), nullable=False),
    sa.Column('ssh_port', sa.Integer(), nullable=False),
    sa.Column('login', sa.String(length=100), nullable=False),
    sa.Column('password', sa.String(length=100), nullable=False),
    sa.Column('country_id', sa.Integer(), nullable=False),
    sa.Column('city_id', sa.Integer(), nullable=False),
    sa.Column('status', sa.Enum('active', 'inactive', 'connection failure'), server_default='active', nullable=True),
    sa.Column('was_added', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.ForeignKeyConstraint(['city_id'], ['city.id'], ),
    sa.ForeignKeyConstraint(['country_id'], ['country.id'], ),
    sa.ForeignKeyConstraint(['provider_id'], ['provider.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('allowed_ips_orders',
    sa.Column('allowed_ip_id', sa.Integer(), nullable=True),
    sa.Column('order_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['allowed_ip_id'], ['allowed_ip.id'], ),
    sa.ForeignKeyConstraint(['order_id'], ['order.id'], )
    )
    op.create_table('proxy',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('port_https', sa.Integer(), nullable=False),
    sa.Column('login', sa.String(length=50), nullable=False),
    sa.Column('password', sa.String(length=50), nullable=False),
    sa.Column('server_id', sa.Integer(), nullable=True),
    sa.Column('status', sa.Enum('available', 'sold'), server_default='available', nullable=True),
    sa.Column('authorization_type', sa.Enum('by_ip_address', 'by_password'), server_default='by_password', nullable=True),
    sa.Column('reload_type', sa.Enum('by_time', 'by_link'), nullable=True),
    sa.Column('reload_period', sa.Integer(), server_default='0', nullable=True),
    sa.Column('reload_link', sa.String(length=50), nullable=True),
    sa.Column('was_added', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['server_id'], ['server.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('login'),
    sa.UniqueConstraint('password'),
    sa.UniqueConstraint('port_https')
    )
    op.create_table('server_categories',
    sa.Column('category_id', sa.Integer(), nullable=True),
    sa.Column('server_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
    sa.ForeignKeyConstraint(['server_id'], ['server.id'], )
    )
    op.create_table('orders_proxies',
    sa.Column('order_id', sa.Integer(), nullable=True),
    sa.Column('proxy_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['order_id'], ['order.id'], ),
    sa.ForeignKeyConstraint(['proxy_id'], ['proxy.id'], )
    )
    op.create_table('proxies_users',
    sa.Column('proxy_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['proxy_id'], ['proxy.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('proxies_users')
    op.drop_table('orders_proxies')
    op.drop_table('server_categories')
    op.drop_table('proxy')
    op.drop_table('allowed_ips_orders')
    op.drop_table('server')
    op.drop_table('order')
    op.drop_table('sites_categories')
    op.drop_table('payment')
    op.drop_table('city')
    op.drop_table('allowed_ip')
    op.drop_table('user')
    op.drop_table('stats')
    op.drop_table('site')
    op.drop_table('provider')
    op.drop_table('country')
    op.drop_table('category')
    op.drop_table('admin_user')
    # ### end Alembic commands ###
